-- «•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»«•»
{-
    $Author$
    $Revision$
    $Id$
    $Date$
-}


--- This package mirrors the content of java.lang.Math
--- For details see http://download.oracle.com/javase/7/docs/api/java/lang/Math.html
--- Contributed by Daniel Gronau

protected package frege.prelude.Math where

import frege.prelude.PreludeBase(Double, Float, Int, Long, ST, Num)

infixr 15  `**`

protected pure native e         java.lang.Math.E        :: Double
protected pure native pi        java.lang.Math.PI       :: Double
public         native random    java.lang.Math.random   :: () -> ST s Double
-- to save typing we define a class and instantiate it with Double and Float

protected class PrimitiveFloating number where
    protected pure native nativeAbs       java.lang.Math.abs      :: number -> number
    protected pure native acos            java.lang.Math.acos     :: number -> Double
    protected pure native asin            java.lang.Math.asin     :: number -> Double
    protected pure native atan            java.lang.Math.atan     :: number -> Double
    protected pure native atan2           java.lang.Math.atan2    :: number -> number -> Double
    protected pure native cbrt            java.lang.Math.cbrt     :: number -> Double
    protected pure native ceil            java.lang.Math.ceil     :: number -> Double
    protected pure native copySign        java.lang.Math.copySign :: number -> number -> number
    protected pure native cos             java.lang.Math.cos      :: number -> Double
    protected pure native cosh            java.lang.Math.cosh     :: number -> Double
    protected pure native exp             java.lang.Math.exp      :: number -> Double
    protected pure native expm1           java.lang.Math.expm1    :: number -> Double
    protected pure native nativeFloor     java.lang.Math.floor    :: number -> Double
    protected pure native getExponent     java.lang.Math.getExponent :: number -> Int
    protected pure native hypot           java.lang.Math.hypot    :: number -> number -> Double
    protected pure native ieeeRemainder   java.lang.Math.IEEEremainder :: number -> number -> Double
    protected pure native log             java.lang.Math.log      :: number -> Double
    protected pure native log10           java.lang.Math.log10    :: number -> Double
    protected pure native log1p           java.lang.Math.log1p    :: number -> Double
    protected pure native nativeMin       java.lang.Math.min      :: number -> number -> number
    protected pure native nativeMax       java.lang.Math.max      :: number -> number -> number
    protected pure native nextAfter       java.lang.Math.nextAfter:: number -> number -> number
    protected pure native nextUp          java.lang.Math.nextUp   :: number -> number
    protected pure native **              java.lang.Math.pow      :: number -> number -> Double
    protected pure native pow             java.lang.Math.pow      :: number -> number -> Double
    protected pure native rint            java.lang.Math.rint     :: number -> Double
    protected pure native round           java.lang.Math.round    :: number -> Long
    protected pure native scalb           java.lang.Math.scalb    :: number -> Int -> number
    protected pure native signum          java.lang.Math.signum   :: number -> number
    protected pure native sin             java.lang.Math.sin      :: number -> Double
    protected pure native sinh            java.lang.Math.sinh     :: number -> Double
    protected pure native sqrt            java.lang.Math.sqrt     :: number -> Double
    protected pure native tan             java.lang.Math.tan      :: number -> Double
    protected pure native tanh            java.lang.Math.tanh     :: number -> Double
    protected pure native toDegrees       java.lang.Math.toDegrees:: number -> Double
    protected pure native toRadians       java.lang.Math.toRadians:: number -> Double
    protected pure native ulp             java.lang.Math.ulp      :: number -> number


instance PrimitiveFloating Double
instance PrimitiveFloating Float

-- additional functions according Haskell Prelude

sqr :: Num a => a -> a
sqr x = x * x
